$(function() {

    var startDate = new Date(2015, 11, 20);
    var endDate = new Date(2015, 11, 25);
    var $alert = $('#my-alert');
    var taNum = 1;
    var odNum = 2;
    //余额
    function walletS(data){
      $(".balance").html(data.parkManager.overage);
    }
     function walletE(data){
      alert("获取信息失败");
    }

    function SearchS(data){ 
      if( data.status == false ) {
        alert("获取信息失败");
        return ;
      }
      $.each(data.recordList,function(i,item){
          var node = $(".clonetr").eq(0).clone(true);
      
          node.find(".orderNum").html(item.orderNum);
          node.find(".startDate").html(item.startDate);
          node.find(".endDate").html(item.endDate);
       
          node.find(".price").html(item.parkingPlace.partPrice);
          node.find(".Number").html(item.parkingPlace.parkingPlaceId);
          node.find(".carNumber").html(item.car.carNumber);
          node.find(".payment").html(item.payment);
          node.find(".income").html(item.payment);
          node.removeClass("hide");
          $(".mytbody"+taNum).append(node);
      });
      $(".mytbody"+taNum).removeClass("hide");
      $(".mytbody"+odNum).addClass("hide");
    }

    function SearchE(data){
      alert("信息查询失败error");
    }

    /**/
    $('#my-start').datepicker().on('changeDate.datepicker.amui', function(event) {
        if (event.date.valueOf() > endDate.valueOf()) {
          $alert.find('p').text('开始日期应小于结束日期！').end().show();
        } else {
          $alert.hide();
          startDate = new Date(event.date);
          $('#my-startDate').text($('#my-start').data('date'));
        }
        $(this).datepicker('close');
      });

    $('#my-end').datepicker().
      on('changeDate.datepicker.amui', function(event) {
        if (event.date.valueOf() < startDate.valueOf()) {
          $alert.find('p').text('结束日期应大于开始日期！').end().show();
        } else {
          $alert.hide();
          endDate = new Date(event.date);
          $('#my-endDate').text($('#my-end').data('date'));
        }
        $(this).datepicker('close');
      });

      $(".nav li").click(function(){
         $(".nav li").each(function(){
            $(this).find("a").removeClass("liActive");
         })
         $(this).find("a").addClass("liActive");
         $("tbody").each(function(){
            $(this).html();
         });
      })
      /**/

      //  按日期查询
      $(".plSearch").click(function(){
           var startDate = $('#my-startDate').text();
           var endDate = $('#my-endDate').text();
           var pageIndex = 1;
           taNum = 2;
           odNum =1;
           $(".mytbody"+taNum).html("");
           console.log(startDate+","+endDate);
           Ajax({
            url:"http://app.souchewei.net/record/queryOrderRecord",
            type: "post",
            data:{"startDate":startDate,"endDate":endDate,"pageIndex":pageIndex},
            datatype:'jsonp',
            call1: SearchS,
            call2: SearchE
           });
        });

      //  按订单号查询
      $(".ddSearch").click(function(){
           taNum = 2;
           odNum = 1;
           var ddNum = $('.w-text').val();
           $(".mytbody"+taNum).html("");
           Ajax({
            url:"http://app.souchewei.net/record/queryByOrderNum",
            data:{"orderNum":ddNum},
            type: "post",
            datatype:'jsonp',
            call1: SearchS,
            call2: SearchE
           });
        });

      //  加载车场信息
        Ajax({
            url:"http://app.souchewei.net/parkManager/detail",
            call1: walletS,
            call2: walletE
        });
     
     
});